package com.springboot.autoconfigure.oss.service;

import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import com.springboot.autoconfigure.oss.config.LocalConfigPropertis;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * @author zehua
 * @date 2023/8/11 9:25
 * @Description TODO
 * @since V1.1.0
 */
public class DefaultLocalFilePathHelper implements AbstractLocalFilePathHelper{

    private final FileNameService fileNameService;
    public DefaultLocalFilePathHelper(FileNameService fileNameService) {
        this.fileNameService = fileNameService;
    }

    @Override
    public String getFileUrlPath(LocalConfigPropertis localConfigPropertis, File localPath,String fileName) {
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append(localConfigPropertis.getDomain());
        stringBuilder.append(StrUtil.SLASH);

        if (StringUtils.isNoneBlank(localConfigPropertis.getUrlPrefix())){
            stringBuilder.append(localConfigPropertis.getUrlPrefix());
            stringBuilder.append(StrUtil.SLASH);
        }
        stringBuilder.append(fileNameService.getFilePath().replace(File.separator, "/"));
        stringBuilder.append(fileName);
        return stringBuilder.toString();
    }
}
